<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/8/28
 * Time: 14:17
 * 余额支付日志文件记录
 */

namespace App\Admin\Controllers\Market;

use App\Admin\Forms\CouponProfile;
use App\Admin\Forms\UserProfile;
use App\Models\RechargeRecord;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Grid;

class RechargeController extends AdminController
{
    public $title = '充值流水';

    protected function grid()
    {

        return new Grid(new RechargeRecord(), function (Grid $grid) {
            $grid->model()->with(['company', 'user'])->orderByDesc('created_at');
            $grid->column('sn', '流水号');
            $grid->column('sn_number', '订单编号');
            $grid->column('status', '订单状态')->display(function ($type) {
                return RechargeRecord::STATUS[$type];
            });
            $grid->column('user.name', '姓名');
            $grid->column('user.phone', '手机号');
            $grid->column('type', '变动类型')->display(function ($type) {
                return RechargeRecord::TYPE[$type];
            });
            $grid->column('amount', '变动前余额');
            $grid->column('price', '变动金额');
            $grid->column('after_price', '变动后余额');
            $grid->column('company.name', '所属公司');
            $grid->column('优惠券')->display('优惠券')->modal('送优惠券', CouponProfile::make(['user_id'=>$grid->user_id->hide()]));
            $grid->column('充值')->display('充值')
                ->modal('平台充值', UserProfile::make()->payload(['user_id'=>$grid->user_id->hide()]));
            $grid->column('created_at', '操作时间');
            $grid->disableActions();
            $grid->disableViewButton();
            $grid->disableBatchDelete();
            $grid->disableCreateButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('user.name', '姓名');
                $filter->like('user.phone', '手机号');
                $filter->like('sn_number', '订单编号');

            });
        });

    }
}